105-2008: Using the SAS® DATA Step and PROC SQL to Create Macro Arrays

نویسنده

  • Stuart Long
چکیده

Successful analysis in SAS often requires lengthy repetitive steps; the same code is executed on numerous data points. Iteration of SAS code is often easily achieved with the use of Macro Arrays. The programmer can employ numerous methods for creating these arrays, as well as choosing among different structural designs. PROC SQL and the SAS DATA step can each provide clear advantages to the creation of these arrays. PROC SQL and the DATA step can take advantage of descriptive information that is available to the programmer in the data set header line. This paper will discuss the benefits of the assignment of values to macro-variable array elements using CALL SYMPUTX() in the DATA step and the SELECT INTO expression in PROC SQL. This paper is intended for SAS programmers who have a working knowledge of Base SAS and the SAS Macro Facility. INTRODUCTION The elements of macro variables are text strings. These strings can consist of variable names, data set names, character strings, procedure or DATA step options, or any other list of items or code that can be processed by the SAS System. This paper will concentrate on the aspect of iteration and will be further narrowed to deal with the iteration of variable names, or variable descriptive information, as used by SAS procedures and DATA steps. Often an analysis will require iteration of SAS procedures for numerous data points. Executing a PROC MEANS or PROC FREQ for multiple variables can be as simple as listing the variables in the VAR or TABLES statement. However, if a programmer wishes to reduce the amount of output which must be reviewed or if the iteration of procedures is quite complex, it may be more prudent to process the analysis one data point(e.g. name of variable) at a time. One common method of achieving this type of iteration is with the use of Macro Arrays. If the list of data points is numbered in the tens, hundreds, or possibly even thousands, Macro Arrays can offer the programmer a method of reducing the amount of code that must be created. Macro Arrays are normally used in one of two constructs. 1) Array of Macro Variables: An ordinal list of macro variables where each contains one element to be processed. 2) Macro Variable Array: One macro variable containing the entire array of elements to be processed. The simplest way to create an Array of Macro Variables is by entering an ordinal sequence of macro variable assignments using %LET statements: %LET disease1=diabetes; %LET disease2=hbp; %LET disease3=cvd; %LET disease4=asthma; The Macro Variable Array can be assigned using one %LET statement: %LET disease=diabetes hbp cvd asthma; The SAS DATA step and PROC SQL can serve as excellent tools for creating these macro variable constructs. The method which a programmer chooses to use may vary, depending on programming preferences. ARRAYS Have you ever wished you could run code like the following? ARRAY symptom {*} symptom1-symptom40; ARRAY disease {*} diabetes--asthma; DO i = 1 TO DIM(symptom); DO j = 1 TO DIM(disease); PROC FREQ DATA=mydata; TABLES symptom{i}*disease{j} / CHISQ RELRISK; RUN; END; END; Applications Development SAS Global Forum 2008

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

When PROC APPEND May Make More Sense Than the DATA STEP

Virtually all SAS programmers (with apologies to diehard SQL codeslingers) tend to use a simple SET statement in the DATA STEP when concatenating two or more datasets in their programs. Use of the SET statement is generally the most logical and practical approach because the required code is typically very succinct and the process in most instances involves concatenation of only two datasets. H...

متن کامل

Contrasting programming techniques for summarizing voluminous SAS output using the SAS Output Delivery System (ODS) (PROC FREQ as an example) Stuart Long, Westat

SAS® ODS provides programmers with the ability to extract selected information from a procedure and store it in datasets. Such datasets can then be combined to summarize the results from numerous procedures. The SAS Macro facility can be used to execute and extract information from repetitively called SAS procedures. “Macro Variable Arrays” can simplify the extraction of information from SAS pr...

متن کامل

191-2007: Model Selection in PROC MIXED—A User-Friendly SAS® Macro Application

A user-friendly SAS macro application to perform all possible model selection of fixed effects including quadratic and cross products within a user-specified subset range in the presence of random and repeated measures effects using SAS PROC MIXED is available. This macro application, ALLMIXED2 will complement the model selection option currently available in the SAS PROC REG for multiple linea...

متن کامل

A Hands-On Tour Inside the World of PROC SQL.PDF

Structured Query Language (PROC SQL) is a database language found in the base-SAS software. It enables access to data stored in SAS data sets or tables using a powerful assortment of statements, clauses, options, functions, and other language features. This hands -on workshop presents core concepts of this powerful language as well as its many applications, and is intended for SAS users who des...

متن کامل

Sugi 20 Designer Graphics - Anatomy of Some Sas Macros for Statistical Graphics

For statistical graphics—where the goal is to gain insight into the displays combining plots, charts, and explanatory text. You create data—SAS/GRAPH procedures alone often do not go far enough in the individual panels in separate steps or jobs; when you replay providing the tools for the most effective visual displays. In these them in a template the individual pieces are automatically rescale...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

برای دانلود متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2008